<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        //至少使用2种方式实现以下data数据的深拷贝
        const data = [ {
                id:1,
                name:'Huawei Mate50 pro',
                price:6998
            },{
                id:2,
                name:'Apple 18',
                price:12998,
            },{
                id:3,
                name:'xiaomi 12',
                price:3998
        }]
        //第一种方式:
        let str = JSON.stringify(data)
        let obj1 = JSON.parse(str)
        

        //第二种方式：
        let deepClone = (obj) => {
            if (!obj || typeof obj !== 'object') {
                return {}
            }
            let newObj = Array.isArray(obj) ? [] : {}
            for (let key in obj) {
                let value = obj[key]
                newObj[key] = typeof value === 'object' ? deepClone(value) : value
            }
            return newObj
        }

        let obj2 = deepClone(data)

        

    </script>
</body>
</html>